package cn.finder.httpcommons.request;

import java.util.HashMap;
import java.util.Map;

import cn.finder.httpcommons.response.ApiResponse;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;

/***
 * 默认的Request实现 主要用于 直接传输里面的数据  , 数据直接是当前Request的中的属性
 * 
 * @author whl
 * 
 * @param <T>
 */
public abstract class XmlStringRequest<T extends ApiResponse> extends
		StringDataRequest<T> {

	
	
	
	public XmlStringRequest() {
		super();
	}

	/***
	 * 额外参数
	 */
	protected Map<String, String> parameters=new HashMap<String, String>();

	public void addParameter(String key, String value) {
		if (this.parameters == null) {
			this.parameters = new HashMap<String, String>();
		}
		this.parameters.put(key, value);

	}

	/***
	 * 获取API 接口 KEY
	 */
	public abstract String apiName();

	public Map<String, String> parameters() {

		XStream xs = new XStream(new DomDriver("UTF-8",new XmlFriendlyNameCoder("-_", "_")));
		
		xs.alias("xml", this.getClass());
	    data = xs.toXML(this);
	    
		return parameters;

	}

	
	public abstract void validate();
	

	
}
